package com.txhy.certificatechain.ui.activity.user;

import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.txhy.certificatechain.R;
import com.txhy.certificatechain.model.bean.UserBean;
import com.txhy.certificatechain.presenter.user.OpenAccountPresenter;
import com.txhy.certificatechain.ui.activity.base.BaseActivity;
import com.txhy.certificatechain.ui.view.account.OpenAccountView;
import com.txhy.certificatechain.utils.PrefUtil;
import com.txhy.certificatechain.utils.ToastUtil;
import com.txhy.certificatechain.utils.UIUtils;

import butterknife.BindView;
import butterknife.OnClick;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2018-2030, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: OpenAccountActivity.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: 账户开通
 * 创建时间: 2018/9/20 10:33
 * 更新时间：2018/9/20 10:33
 * -----------------------------------------------------------------
 * 2018/9/20 10:33: 创建 OpenAccountActivity.java (侯建军);
 * -----------------------------------------------------------------
 */
public class OpenAccountActivity extends BaseActivity<OpenAccountView,OpenAccountPresenter> implements OpenAccountView{

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_money)
    TextView tv_money;
    private UserBean.DataEntity.MapEntity user;
    private UserBean userBean;


    @Override
    protected OpenAccountPresenter createPresenter() {
        return new OpenAccountPresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_open_account;
    }

    @Override
    public void initView() {
        super.initView();
        tv_title.setText(UIUtils.getString(R.string.kaitongjiaoyi));
        user= PrefUtil.getUserBean(OpenAccountActivity.this);
        userBean= PrefUtil.getUserString(OpenAccountActivity.this);
        showWaitingDialog("正在加载数据...");
        mPresenter.getMsg(user.getId()+"");

    }

    @OnClick({R.id.im_left, R.id.tv_kaiTong})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.im_left:
                finish();
                break;
            case R.id.tv_kaiTong:
                mPresenter.openAccount(user.getId()+"",user.getUserType(),"2000");

                break;
        }
    }

    @Override
    public void getMsgSuccess(String user) {
        tv_money.setText(user);
        hideWaitingDialog();
    }

    @Override
    public void getMsgFail(String msg) {
        ToastUtil.showLong(OpenAccountActivity.this,msg);
        hideWaitingDialog();
    }

    @Override
    public void openSuccess(String user) {
        userBean.getData().getMap().get(PrefUtil.getShengType(OpenAccountActivity.this)).setAccountNo(user);
        PrefUtil.setUserString(OpenAccountActivity.this,new Gson().toJson(userBean));
//        startActivity(new Intent(OpenAccountActivity.this, OpenAccountSuccessActivity.class));
        finish();
    }
    @Override
    public void openFail(String msg) {
        ToastUtil.showLong(OpenAccountActivity.this,msg);
    }
}
